<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/contatos/consulta');?>">Contato</a></li>
  <li class="active">Edita</li>
</ol>
		<div class="clone-wrapper">
				<fieldset class="cad">
					<legend>Editar Contato</legend>
					<form class="form-horizontal" role="form" id="form">
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Ramal</label>
							<div class="col-sm-2">
								<input type="text" id="ramal"  name="ramal" value="<?php echo $contato->ramal_ramal; ?>" class="form-control input-sm" id="" placeholder="Digite o ramal">
								<input type="hidden" id="idramal" name="idramal" value="<?php echo $contato->ramal_id; ?>" class="form-control input-sm" id="" />
								<input type="hidden" id="idcontato" name="idcontato" value="<?php echo $contato->id; ?>" class="form-control input-sm" id="" />
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Nome Contato</label>
							<div class="col-sm-3">
								<input type="text" id="contato" name="contato" value="<?php echo $contato->nomecontato; ?>"  class="form-control input-sm"  placeholder="Nome Contato">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Celular</label>
							<div class="col-sm-2">
								<input type="text" id="celular"  name="celular" value="<?php echo $contato->celular; ?>" class="form-control input-sm" id="" placeholder="Digite o celular">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Cargo</label>
							<div class="col-sm-3">
								<input type="text" id="cargo" name="cargo" value="<?php echo $contato->cargo; ?>"  class="form-control input-sm" placeholder="Cargo">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">E-mail</label>
							<div class="col-sm-3">
								<input type="email" id="email" name="email" value="<?php echo $contato->email; ?>"  class="form-control input-sm" placeholder="E-mail">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Tags</label>
							<div class="col-sm-3">
								<input type="text" class="form-control input-sm" value="<?php echo $contato->tag; ?>"  id="tag" name="tag" placeholder="Digite as tags separadas por virgula">
							</div>
						</div>
						<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
						<!--<a href="#" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-plus"></span>Adicionar outro Contato</a>
						<a href="#" class="removerCampo"><span class="glyphicon glyphicon-plus"></span></a>-->
							</p>
						</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
							<?php 
								$data = array('name'=>'salvar','type' => 'submit','class' => 'btn btn-primary','content' =>'Editar');
								echo form_button($data);
							?>
							<a id="cancelar" href="<?php echo base_url('index.php/contatos/consulta');?>" class="btn btn-default"></span>Cancelar</a>
							</div>
						</div>
						</form>
					</fieldset>
		</div>

</div>

	<script language="javascript" type="text/javascript">
	$(document).ready(function(){
		$( "#ramal" ).focus();
		var maskBehavior = function (val) {
			return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
		},
		options = {onKeyPress: function(val, e, field, options) {
				field.mask(maskBehavior.apply({}, arguments), options);
			}
		};
		$("#celular").mask(maskBehavior, options);
		$( "#ramal" ).autocomplete({
					source: "<?php echo base_url('index.php/ramais/consultaJson');?>",
					minLength: 2,
					select: function( event, ui ) {
						$("#idramal").val(ui.item.id);
					}
		});
		
		$('#form').validate({  
			rules: {  
				ramal: { 
					required: true, 
					remote:'<?php echo base_url('index.php/ramais/validaCadRamal');?>'
				},
				contato: {
					required:true
				},
				cargo: { required: true }
				
			},  
			messages: {  
				ramal: { required: 'Preencha o campo', remote: 'Ramal nao existe!' },
				contato: { required: 'Preencha o campo'},
				cargo: { required: 'Preencha o campo'}
			},
			submitHandler: function( form ){  
				var dados = $( form ).serialize();  
				$.ajax({  
					type: "POST",  
					url: "<?php echo base_url('index.php/contatos/editar');?>",  
					data: dados,  
					success: function( data )  
					{  
						//alertify.alert( data );
						alert( data );
						window.location = '<?php echo base_url('index.php/contatos/consulta');?>';
					}  
				});  
				return false;  
			} 
		}); 
	});
		
	</script>
	</body>
</html>